package cn.tedu.yl.doctors.service;

import cn.tedu.yl.base.response.PageData;
import cn.tedu.yl.department.mapper.DepartmentMapper;
import cn.tedu.yl.department.pojo.Department;
import cn.tedu.yl.doctors.mapper.DoctrosMapper;
import cn.tedu.yl.doctors.pojo.Doctors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DoctrosService {

    @Autowired
    private DoctrosMapper articleRepository;

    public PageData getAllDepartment() {
        PageData pageData = new PageData();
        pageData.setList(articleRepository.findAll());
        pageData.setTotal(articleRepository.findAll().size());
        return pageData;
    }

    public Doctors getDepartmentById(Long id) {
        return articleRepository.findById(id).orElse(null);
    }


    public Doctors createArticle(Doctors department) {
        department.setCreateTime(LocalDateTime.now());
        department.setUpdateTime(LocalDateTime.now());
        return articleRepository.save(department);
    }
    public Doctors updateArticle(Long id, Doctors department) {
        Doctors department1 = articleRepository.findById(id).orElse(null);
        if (department1 != null) {
            department1.setName(department.getName());
            department1.setAvatar(department.getAvatar());
            department1.setProfessionalId(department.getProfessionalId());
            department1.setCampusId(department.getCampusId());
            department1.setDepartmentId(department.getDepartmentId());
            department1.setLabels(department.getLabels());
            department1.setIntroduce(department.getIntroduce());
            department1.setUpdateTime(LocalDateTime.now());
            department1.setStatus(department.getStatus());
            return articleRepository.save(department1);
        }
        return null;
    }

    public void deleteDepartment(Long id) {
        articleRepository.deleteById(id);
    }
}
